// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.iso.sprite.shapers;

import zombie.core.textures.TextureDraw;
import zombie.debug.DebugOptions;

public class SpritePadding {
    public static void applyPadding(
        TextureDraw ddraw, float xPadLeft, float yPadUp, float xPadRight, float yPadDown, float uPadLeft, float vPadUp, float uPadRight, float vPadDown
    ) {
        float float0 = ddraw.x0;
        float float1 = ddraw.y0;
        float float2 = ddraw.x1;
        float float3 = ddraw.y1;
        float float4 = ddraw.x2;
        float float5 = ddraw.y2;
        float float6 = ddraw.x3;
        float float7 = ddraw.y3;
        float float8 = ddraw.u0;
        float float9 = ddraw.v0;
        float float10 = ddraw.u1;
        float float11 = ddraw.v1;
        float float12 = ddraw.u2;
        float float13 = ddraw.v2;
        float float14 = ddraw.u3;
        float float15 = ddraw.v3;
        ddraw.x0 = float0 - xPadLeft;
        ddraw.y0 = float1 - yPadUp;
        ddraw.u0 = float8 - uPadLeft;
        ddraw.v0 = float9 - vPadUp;
        ddraw.x1 = float2 + xPadRight;
        ddraw.y1 = float3 - yPadUp;
        ddraw.u1 = float10 + uPadRight;
        ddraw.v1 = float11 - vPadUp;
        ddraw.x2 = float4 + xPadRight;
        ddraw.y2 = float5 + yPadDown;
        ddraw.u2 = float12 + uPadRight;
        ddraw.v2 = float13 + vPadDown;
        ddraw.x3 = float6 - xPadLeft;
        ddraw.y3 = float7 + yPadDown;
        ddraw.u3 = float14 - uPadLeft;
        ddraw.v3 = float15 + vPadDown;
    }

    public static void applyPaddingBorder(TextureDraw ddraw, float borderThickness, float uvFraction) {
        float float0 = ddraw.x1 - ddraw.x0;
        float float1 = ddraw.y2 - ddraw.y1;
        float float2 = ddraw.u1 - ddraw.u0;
        float float3 = ddraw.v2 - ddraw.v1;
        float float4 = float2 * borderThickness / float0;
        float float5 = float3 * borderThickness / float1;
        float float6 = uvFraction * float4;
        float float7 = uvFraction * float5;
        applyPadding(ddraw, borderThickness, borderThickness, borderThickness, borderThickness, float6, float7, float6, float7);
    }

    public static void applyIsoPadding(TextureDraw ddraw, SpritePadding.IsoPaddingSettings settings) {
        if (DebugOptions.instance.Terrain.RenderTiles.IsoGridSquare.IsoPadding.getValue()) {
            SpritePadding.IsoPaddingSettings.IsoBorderSetting isoBorderSetting = settings.getCurrentZoomSetting();
            float float0 = isoBorderSetting.borderThickness;
            float float1 = isoBorderSetting.uvFraction;
            applyPaddingBorder(ddraw, float0, float1);
        }
    }

    public static class IsoPaddingSettings extends SpritePaddingSettings.GenericZoomBasedSettingGroup {
        public SpritePadding.IsoPaddingSettings.IsoBorderSetting ZoomedIn = new SpritePadding.IsoPaddingSettings.IsoBorderSetting(1.0F, 0.99F);
        public SpritePadding.IsoPaddingSettings.IsoBorderSetting NotZoomed = new SpritePadding.IsoPaddingSettings.IsoBorderSetting(1.0F, 0.99F);
        public SpritePadding.IsoPaddingSettings.IsoBorderSetting ZoomedOut = new SpritePadding.IsoPaddingSettings.IsoBorderSetting(2.0F, 0.01F);

        public SpritePadding.IsoPaddingSettings.IsoBorderSetting getCurrentZoomSetting() {
            return getCurrentZoomSetting(this.ZoomedIn, this.NotZoomed, this.ZoomedOut);
        }

        public static class IsoBorderSetting {
            public float borderThickness;
            public float uvFraction;

            public IsoBorderSetting() {
            }

            public IsoBorderSetting(float _borderThickness, float _uvFraction) {
                this.borderThickness = _borderThickness;
                this.uvFraction = _uvFraction;
            }
        }
    }
}
